package net.osweb.core.tools.utils.crm;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
	private RegexUtil(){}
	
	/**
	 * 解析话题
	 * @param str
	 * @return
	 */
	public static List<String> regTrends(String str){
		List<String> list = new ArrayList<String>();
		
		if(str == null || str.trim().length() <= 0)
			return list;
		
//		Pattern p=Pattern.compile("@[\\u4e00-\\u9fa5\\w\\-]+");
//		Pattern p=Pattern.compile("#[\u4e00-\u9fa5a-zA-Z0-9@_]*#");
		Pattern p=Pattern.compile("#([^\\#|.]+)#");
		
		Matcher m=p.matcher(str);
		while(m.find()){
			String tmp = m.group();
//			String title = new String(tmp.substring(1, tmp.length()-1));
//			list.add(title);
			list.add(tmp);
		}
		return list;
	}
	
	public static List<String> regAtme(String str){
		List<String> list = new ArrayList<String>();
		
		if(str == null || str.trim().length() <= 0)
			return list;	

		//@昵称   
		Pattern p=Pattern.compile("@[\\u4e00-\\u9fa5\\w\\-]+");
		
		Matcher m=p.matcher(str);
		while(m.find()){
			String tmp = m.group();
			list.add(tmp);
		}
		return list;
		
	}
	
	/**
	 * 解析@
	 * @param str
	 * @return
	 */
	public static List<String> regAt(String str){
		return null;
	}
	
	
	public static void main(String[] args) {
		//String str ="#a a#222#333#中我#英文#是这样的#9494##<h1>me</h1>#";
		
		String str2 ="@12323@4444 wahahah@13";
		
//		String tt = StringUtil.filterHtml(str.trim());
		test2(str2);
//		test(str);
//		List list = regTrends(tt);
//		System.out.println(list);
	}	
	
	
	public static void test(String str){
		// #aaa#    #333#   #英文#
	//	Pattern pattern = Pattern.compile("/#[\u4e00-\u9fa5a-zA-Z0-9@_]*#/");
		//var reg=new RegExp("^@([\x{4e00}-\x{9fa5}A-Za-z0-9_]*)$u"); 
		//	var reg=new RegExp("^#([\x{4e00}-\x{9fa5}A-Za-z0-9_]*)#$u"); 
		Pattern p=Pattern.compile("#[\u4e00-\u9fa5a-zA-Z0-9@_]*#");
		Matcher m=p.matcher(str);
		while(m.find()){
			System.out.println("s:"+m.group());
		}		
	}
	
	public static void test2(String str){
		Pattern p=Pattern.compile("@[\\u4e00-\\u9fa5\\w\\-]+");
		Matcher m=p.matcher(str);
		while(m.find()){
			System.out.println("s:"+m.group());
		}	
	}
	
}

/**
//解析	
//var reg=new RegExp("^@([\x{4e00}-\x{9fa5}A-Za-z0-9_]*)$u"); 
//	var reg=new RegExp("^#([\x{4e00}-\x{9fa5}A-Za-z0-9_]*)#$u"); 
var reg=/#[\u4e00-\u9fa5a-zA-Z0-9@_]*#/g; 
var tmpTrends = ctxt.match(reg);
var trends = "";
for(var i=0;i<tmpTrends.length;i++){
	trends += trimTrend(tmpTrends[i])+",";
}
trends=trends.substring(0,trends.length-1);
document.getElementById("trends").value=trends ;	
**/

//sina
//new RegExp("(@|＠)"+scope.$uname+"([^a-zA-Z0-9\u4e00-\u9fa5_]|$)")